package com.smartwasser.yunhtgl.apphtgl.widget;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;

import com.smartwasser.yunhtgl.apphtgl.R;

public class CustomToast {
    private static TextView mTextView;
    private static Toast toastStart;

    public static void showToast(Context context, String message) {
        View toastRoot = LayoutInflater.from(context).inflate(R.layout.toast, null);
        mTextView = toastRoot.findViewById(R.id.message);
        mTextView.setText(message);
        toastStart = new Toast(context);
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        int height = wm.getDefaultDisplay().getHeight();
        toastStart.setGravity(Gravity.TOP, 0, 2 * height / 3);
        toastStart.setDuration(Toast.LENGTH_SHORT);
        toastStart.setView(toastRoot);
        toastStart.show();
    }
}
